package com.wc.算法提高课.C第三章_图论.欧拉回路和欧拉路径.单词游戏;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/22 11:26
 * @description https://www.acwing.com/problem/content/1187/
 */
public class Main {
    /**
     * 思路：把每一个单词当做单向边, 做欧拉路径, 没有的话就无解
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 30, M = 100010;
    static int[] h = new int[N], e = new int[M], ne = new int[M];
    static int[] din = new int[N], dout = new int[N];
    static boolean[] used = new boolean[M];
    static int idx = 1, cnt = 0;
    static int m;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            Arrays.fill(h, 0);
            Arrays.fill(din, 0);
            Arrays.fill(dout, 0);
            Arrays.fill(used, 1, m + 1, false);
            idx = 1;

            m = sc.nextInt();
            for (int i = 0; i < m; i++) {
                char[] s = sc.next().toCharArray();
                int a = s[0] - 'a', b = s[s.length - 1] - 'a';
                add(a, b);
                din[b]++;
                dout[a]++;
            }
            boolean success = true;
            // a代表出度比入度多 1 的点, b 代表入度比出度多 1 的点
            int a = 0, b = 0;
            for (int i = 0; i < 26; i++) {
                if (dout[i] == din[i] + 1) a++;
                if (din[i] == dout[i] + 1) b++;
                if (Math.abs(din[i] - dout[i]) >= 2) {
                    success = false;
                    break;
                }
            }
            if (success && !(a == b && (a == 1 || a == 0))) success = false;
            if (!success) out.println("The door cannot be opened.");
            else {
                int start = 0;
                while (din[start] == 0) start++;
                for (int i = 0; i < 26; i++) {
                    if (dout[i] == din[i] + 1) {
                        start = i;
                        break;
                    }
                }
                dfs(start);
                cnt = 0;
                if (cnt < m) out.println("The door cannot be opened.");
                else out.println("Ordering is possible.");
            }
        }
        out.flush();
    }

    static void dfs(int u) {
        for (int i = h[u]; i > 0; i = h[u]) {
            if (used[i]) continue;
            int j = e[i];
            used[i] = true;
            h[u] = ne[i];
            dfs(j);
            ++cnt;
        }
    }

    static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
